<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('物料维护')" />
	<th:block th:include="include :: list-css" />
	<style type="text/css">
		label.layui-form-label {width: 95px;padding-right: 0px;}
		.layui-form-radio {margin-top:0}
		.importTable{empty-cells:show;border-collapse:collapse;border-spacing:0;}
		.listext th{background:#eee;color:#3366cc;}
		.listext th,.listext td{border:solid 1px #ddd;text-align:left;padding:10px;font-size:14px;}
		
		#importProgress {z-index:20200202;background-color: #000;opacity: 0.3;display:none;}
		.importProgress {width:300px;z-index:20202222;position: fixed;top: 34%;left: 40%;display:none;}
		/* .layui-table-box{overflow-x: auto !important;}
		.layui-table-header{display: inline-block !important;} */
	</style>
</head>
<body>
<div class="main-content">
	<div class="content-right">
		<div class="search-top">
			<span>查询条件</span>
			<a href="javascript:;" layadmin-event="flexible" class="menuBtn">
				<i class="layui-icon layui-icon-spread-left" id="LAY_app_flexible" style="color: #fff;"></i>
			</a>
		</div>
		<div class="panel layout-expand layui-expand-east">
		    <div class="panel-header">
		        <div class="panel-tool" style="text-align: center; width: 26px;height: 30px;line-height: 30px;">
		            <a href="javascript:;" layadmin-event="flexible" class="menuBtn">
		                <i class="layui-icon layui-icon-shrink-right" id="LAY_app_flexible" style="color: #fff;"></i>
		            </a>
		        </div>
		    </div>
		    <div class="panel-body panel-title" style="text-align: center; width: 26px;">查<br>询<br>条<br>件</div>
		</div>
       	<form class="layui-form">
			<th:block th:include="listinclude :: searchRight('page')" />
		</form>
   	</div>
    <div class="mid-content">
		<table class="layui-hide" id="dhtable" lay-filter="ftable"></table>
	</div>
</div>
<!-- 表格头部工作栏-->
<script type="text/html" id="toolbar">
	<div class="layui-btn-container">
		<!-- <div class="layui-btn layui-table-tools importbtn-bg" lay-event="addbtn" shiro:hasPermission="oa:materialassetswarehouse:add">
			<i class="dhicon dh-plus"></i> 新增
        </div> -->
		<!-- <div class="layui-btn layui-btn-danger layui-table-tools" onclick="remove()" shiro:hasPermission="oa:materialassetswarehouse:delete">
            <p class="dhicon dh-remove" style="color:white;font-size:14px"><span class="fa_span">批量删除</span></p>
        </div> -->

		<div class="layui-btn layui-table-tools importbtn-bg" lay-event="exportbtn" shiro:hasPermission="oa:materialassetswarehouse:export">
			<i class="dhicon dh-download"></i> 导出
        </div>
    </div>
</script>
<!-- 表格操作区 -->
<script type="text/html" id="barDh">
    <a class="layui-btn layui-btn-danger layui-btn-xs" onclick="dbbtn('{{d.guid}}','{{d.isAllot}}')" style="{{d.isAllot=='否' ?'background:rgb(67, 219, 21)!important;':'background:rgb(219, 117, 21)!important;'}}" shiro:hasPermission="oa:materialmaintenance:edit">{{d.isAllot=='否' ?'调拨' :'停止'}}</a>  
    <!-- <a class="layui-btn layui-btn-danger layui-btn-xs" onclick="editbtn('{{d.guid}}','{{d.code}}')" shiro:hasPermission="oa:materialmaintenance:edit">修改</a>  
    <a class="layui-btn layui-btn-danger layui-btn-xs" onclick="remove('{{d.guid}}','{{d.code}}')" style="background: rgb(228, 69, 69)!important;" shiro:hasPermission="oa:materialmaintenance:edit">删除</a>    -->
</script>


<th:block th:include="include :: footer" />
<th:block th:include="include :: businessJS" />
<th:block th:include="include :: searchJS" />
<th:block th:include="listinclude :: list-templeat" />
<script th:inline="javascript">
	/*<![CDATA[*/
	var prefix = ctx + "oa/materialassetswarehouse";
	var gridColumns = [[${gridColumns}]], 
		importFields =[[${importFields}]],
		moduleTable =[[${moduleTable}]];
	/*]]>*/
</script>
<script type="text/javascript">
var element,thStr;
var fieldWidth = {},		//导入列表字段宽度
	filedRequired = {},		//导入列表必填字段
	dateFiled = [],			//导入列表日期字段
	hasNull = false;		//导入数据必填字段有空值
$.each(gridColumns.dictionaryForPageFieldList,function(i,v){
	fieldWidth[v.fields] = v.fieldFrontWidth
	if(v.fieldFrontRequired)filedRequired[v.fields] = v.fieldName;
	if(v.fieldFrontType == 't_date')dateFiled.push(v.fields);
})
var $,layer,laydate,form,table,wherestr={};
layui.use(['table','laydate','form','layer','jquery','element'], function () {
	$ = layui.$, layer = layui.layer,laydate = layui.laydate , form = layui.form, table = layui.table, element = layui.element;
	serachRender();//查询条件初始渲染集合
	changeDropdown('fSl');//导入窗口——税率下拉可编辑赋事件
	$.tablelist.init({
		elem: '#dhtable'
		,modalName: "产品信息"
		,url: prefix + '/list'
		,updateUrl: prefix + "/edit?guid={id}"
		,initSort: {field: 'createTime',type: 'asc'}
		,totalRow: gridColumns.totalRow
		,cols: [gridColumns.gridBody]
		,toolbar: '#toolbar'
		,defaultToolbar: [{title:'列设置',layEvent: 'fieldSet',icon: 'layui-icon-set'}] //这里在右边显示
		,height:'full-65'
        ,parseData: function(res){ //res 即为原始返回的数据
			var objpage=sessionStorage.getItem(moduleTable+'checkdata')
			if(objpage){
				objpage=JSON.parse(objpage)
				res.data.map((v,i)=>{
					objpage.map((n,m)=>{
						 if(v.guid==n.guid){
							v.LAY_CHECKED=true
						 }
					})
				})
			}
		}
	});
    
	//监听排序事件 
	table.on('sort(ftable)', function(obj){
		$.tablelist.sort('dhtable',obj);
	});

	//监听行双击事件
    // table.on('rowDouble(ftable)', function (obj) {
    //     console.log("===========rowDouble ");
    //     console.log(obj);
	// 	// window.location.href = "/business/productbasis/edit?guid="+obj.data.guid;
	// 	top.layui.index.openTabsPage(prefix+ "/edit?guid="+obj.data.guid,'商品组装方案 - 修改')

    // });
	//多选复选框
    sessionStorage.setItem(moduleTable+'checkdata','')
    table.on('checkbox(ftable)', function(obj){
		var objpage=sessionStorage.getItem(moduleTable+'checkdata')
		if(obj.type=='all'){//判断是否全选
			var objdata=table.checkStatus('dhtable')
			objdata=objdata.data
			if(obj.checked){//判断是否选中
				if(objpage){
					objpage=JSON.parse(objpage)
					objpage=objpage.concat(objdata)
					objpage=newData(objpage)
				}else{
					objpage=objdata
				}
			}else{
				var objpage=JSON.parse(objpage)
				var deldata=table.cache.dhtable
				objpage=delData(objpage,deldata)
			}
			sessionStorage.setItem(moduleTable+'checkdata',JSON.stringify(objpage))
			
		}else{//点击复选框
			if(objpage){
				objpage=JSON.parse(objpage)
				if(obj.checked){
					objpage.push(obj.data)
				}else{
					objpage.map((v,i)=>{
						if(v.guid==obj.data.guid){
							objpage.splice(i,1)
						}
			    	})
			    }
			}else{
				objpage=[]
				objpage.push(obj.data)
			}
			sessionStorage.setItem(moduleTable+'checkdata',JSON.stringify(objpage))
		}
	});


        //新增修改弹出框
	    window.dialog=function (title,url,width,height,Method){
            $.modal.open(title,url,width,height,function(index){
                var inputForm = $(window.frames["layui-layer-iframe" + index].document).contents().find(".layui-form");
                var is_return = 0,
                    // postStr = [],
                    must_field={},
                    Str = inputForm.serializeFormToJson();

                $.each(gridColumns.dictionaryForPageFieldList,function (fk,fv) {
                    if(fv.fieldFrontRequired)
                        must_field[fv.fields] = fv.fieldName + " 不能为空";
                })
                $.each(must_field,function (k,v) {
                    if(!inputForm.find("#"+k).val()){
                        layer.msg(v);
                        is_return = 1;
                        inputForm.find("#"+k).css('border','1px solid red');
                        inputForm.find("#"+k).focus()
                        return false;
                    }
                })
                if(is_return)return false;
                var deldata = {'infoItems':JSON.stringify(Str)};
                $.operate.post('/oa/materialassetswarehouse/editpost',deldata,function(result){
                    allReload(result)
                });
            })
        }
        function allReload(result){
            if(result.code==0){
                setTimeout(function(){
                    layer.closeAll();
                    table.reload('dhtable');
                }, 1000);
            }
        }

	

	//头工具栏事件
 	table.on('toolbar(ftable)', function(obj){
 	    switch(obj.event){
			case 'addbtn':
					dialog('新增',prefix+ "/edit?guid=0",$(window).width()-300,$(window).height()-250,'addpost');
					break;
	   		case 'exportbtn':
		   		$.ajax({
		   		    url: '/oa/materialassetswarehouse/export',
		   		    type: 'GET',
		   		    data: getWherestr(),
		   		    dataType: 'json',
		   		    beforeSend: function(){
			   			showloadings(true);
		   		    },
		   		    success: function(result){
		   		    	if (result.code == 0) {
					        window.location.href = ctx + "common/download?fileName=" + encodeURIComponent(result.msg) + "&delete=" + true;
					        parent.$('.page-loading').hide();//页面进行了跳转刷新，需要手动关闭页面的加载动画
						} else if (result.code == web_status.WARNING) {
		                   $.modal.alertWarning(result.msg)
		            	} else {
							$.modal.alertError(result.msg);
						}
				   		showloadings(false);
		   		    }
		   		});
	   		break;
			case 'tableFull'://表格展开
				$('.north .layui-form').hide();
				table.reload('dhtable',{
					defaultToolbar: [{title:'收缩',layEvent:'tableShrink',icon:'layui-icon-screen-restore'}],
					height: $(window).height()-$('.north').height()-60<300?'300':$(window).height()-( $('.north').height()+$('.south').height()+12)
				});
			break;
			case 'tableShrink'://表格收缩
				$('.north .layui-form').show();
				table.reload('dhtable',{
					defaultToolbar: [{title:'展开',layEvent:'tableFull',icon:'layui-icon-screen-full'}],
					height: $(window).height()-$('.north').height()-60<300?'300':$(window).height()-( $('.north').height()+$('.south').height()+12)
				});
			break;
	 	    case 'fieldSet':
 	    		filedSet(moduleTable);
          	break;
 	    };
 	});
 });
 //弹出框修改
 function editbtn(guid){
	dialog('修改',prefix+ "/edit?guid="+guid,$(window).width()-300,$(window).height()-250,'addpost');
}
function dbbtn(guid,isAllot){
	$.modal.confirmCom('确定要启用或停止么？',function(result){
		if(isAllot=='是'){
			isAllot='否'
		}else{
			isAllot='是'
		}
		$.post(prefix +'/editpost',{'infoItems':JSON.stringify({guid,isAllot})},function(res){
	    	layer.msg(res.msg);
			if(res.code==0){
				table.reload('dhtable', {page: {curr: 1},where:getWherestr()});
			}
	    });
	});
}
//通过guid彻底删除
function remove(guid,code){
    $.operate.remove("该删除无法恢复，请确认？",prefix + "/delete/",{'infoItems':JSON.stringify([{'guid':guid,code}])},function(result){
		if(result.code==0){
	        setTimeout(function(){
	            layer.closeAll();
	            table.reload('dhtable');
	        }, 1000);
	    }
	});
}

</script>
</body>
</html>